<%-- 
  -- Body New para Subject.
  --
  -- @author ariel.piechotka
--%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %>
<%@ taglib uri="/WEB-INF/struts-html-el-1.2.8.tld" prefix="html-el"%>
<%@ taglib uri="/WEB-INF/struts-logic-el-1.2.8.tld" prefix="logic-el"%>
<%@ taglib uri="/WEB-INF/security.tld" prefix="security" %>

<%@ taglib uri="http://struts.apache.org/tags-bean-el" prefix="bean2"%>

<script src="<html:rewrite page='/protected/script/util.js'/>" type="text/javascript"></script>

<%-- Para EXT --%>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/ext-1.1.1/resources/css/ext-all.css'/>" />

<script src="<html:rewrite page='/protected/script/ext-1.1.1/adapter/ext/ext-base.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/ext-1.1.1/ext-all.js'/>" type="text/javascript"></script>

<script src="<html:rewrite page='/protected/script/calendar/calendar.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/calendar/calendar-setup.js'/>" type="text/javascript"></script>
<script src="<html:rewrite page='/protected/script/calendar/lang/calendar-es.js'/>" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="<html:rewrite page='/protected/script/calendar/style/calendar-blue.css'/>" id="styleFileAnyId"/>



<div class="errors">
    <html:errors />
</div>


<script type="text/javascript">
    /** Crea una materia */
    function createSubject() {
        var codeValue = $("codeId").value;
        var nameValue = $("nameId").value;
        var creditsValue = $("creditsId").value;
        var curriculumValue = $("curriculumId").value;

        if (Util.valid.isBlank(codeValue)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el c&oacute;digo. ');
            $("codeId").focus();
            return;
        }
        if (Util.valid.isBlank(nameValue)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar el nombre. ');
            $("nameId").focus();
            return;
        }
        if (Util.valid.isBlank(curriculumValue)) {
            Ext.MessageBox.alert('Error', 'Debe ingresar la curr&iacute;cula. ');
            $("curriculumId").focus();
            return;
        }
        if (!Util.valid.isBlank(creditsValue) && isNaN(creditsValue)) {
            Ext.MessageBox.alert('Error', 'La cantidad de cr&eacute;ditos debe ser un n&uacute;mero v&aacute;lido. ');
            return;
        }        
        
        var codeObj = $("codeConfirmId");
        var nameObj = $("nameConfirmId");
        var curriculumObj = $("curriculumConfirmId");
        var creditsObj = $("creditsConfirmId");
        
        codeObj.value = codeValue;
        nameObj.value = nameValue;
        curriculumObj.value = curriculumValue;
        creditsObj.value = creditsValue;
        
        var form = $("createSubjectFormId");
        form.submit();
    } 
    
</script>

<%-- El ID del form NO debe ser modificado. Se usa desde el menu --%>
<html:form action="/protected/showNewSubject" styleId="subjectFormId">

    <h2>Creaci&oacute;n de materia</h2>
    
    <div class="subjectEdit">
        <table class="tableData" cellspacing="0">
            <tr>
                <td class="tableDataTitle">
                    Nombre*
                </td>
                <td class="tableDataValue">
                    <html:text property="name" styleId="nameId" alt="Nombre de la materia" maxlength="45"/>
                </td>            
            </tr>
            <tr>
                <td class="tableDataTitle">
                    C&oacute;digo*
                </td>
                <td class="tableDataValue">
                    <html:text property="code" styleId="codeId" alt="Codigo de la materia" maxlength="10"/>
                </td>            
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Cr&eacute;ditos
                </td>
                <td class="tableDataValue">
                    <html:text property="credits" styleId="creditsId" alt="Creditos de la materia" maxlength="4"/>
                </td>            
            </tr>
            <tr>
                <td class="tableDataTitle">
                    Curr&iacute;cula*
                </td>
                <td class="tableDataValue">
                    <html:textarea property="curriculum" styleId="curriculumId" alt="Curricula de la materia" cols="40" rows="15"/>
                </td>            
            </tr>
        </table>
        
        <br/>
        <div id="clear"></div>
    	<p class="mensajeCamposObligatorios">Los campos marcados con un asterisco (*) son obligatorios.</p>
    	<div id="clear"></div>

        <div id="clear">
        </div>
        <div id="clear">
        </div>
        
        <%-- No se valida seguridad ya que SOLO entran aca los q tienen permiso --%>
        <div class="panelButton">
            <input type="button" value="Guardar" onclick="createSubject();" title="Guarda la materia..." class="button">
        </div>  
    
    </div>

</html:form>

<%-- Inyectados por Javascript --%>
<div id="createDivId" class="hideClass">
    <html:form action="/protected/createSubject" styleId="createSubjectFormId">
        <html:hidden property="code" value="" styleId="codeConfirmId" />
        <html:hidden property="name" value="" styleId="nameConfirmId" />
        <html:hidden property="credits" value="" styleId="creditsConfirmId" />
        <html:hidden property="curriculum" value="" styleId="curriculumConfirmId" />
    </html:form>
</div>
